from django.contrib import admin
from .models import Department,HospitalModel,DoctorModel,DoctorTitle,DoctorLabel,DoctorGoodAtModel,HospitalTitleModel
# Register your models here.


class DepartmentAdmin(admin.ModelAdmin):
    ordering = ('id',)
    list_display = ('id','name')
    list_filter = ('name',)






class HospitalAdmin(admin.ModelAdmin):
    ordering = ('id',)
    list_display = ('id','name', 'get_department_name','get_title')
    list_filter = ('name','department__name')


    def get_department_name(self, obj):
       return ",".join([d.name for d in obj.department.order_by('id')])

    def get_title(self, obj):
        try:
            data = obj.title.name
            return data
        except:
            return ""


    get_department_name.short_description = '科室'
    get_title.short_description = "等级"

class DoctorTitleAdmin(admin.ModelAdmin):
    ordering = ('id',)
    list_display = ('id','name')
    list_filter = ('name',)


class DoctorAdmin(admin.ModelAdmin):
    ordering = ('id',)
    list_display = ('id','name', 'department','hospital','avatar_small')
    list_filter = ('name','department__name','hospital__name')


class DoctorLabelAdmin(admin.ModelAdmin):
    ordering = ('id',)
    list_display = ('id','name')
    list_filter = ('name',)


class DoctorGoodAtModelAdmin(admin.ModelAdmin):
    ordering = ('id',)
    list_display = ('id','name','get_department_name')
    list_filter = ('name','department__name')



    def get_department_name(self, obj):
        return ",".join([d.name for d in obj.department.order_by('id')])
    get_department_name.short_description = '科室'


class HospitalTitleModelAdmin(admin.ModelAdmin):
    ordering = ('id',)
    list_display = ('id','name')
    list_filter = ('name',)





admin.site.register(Department, DepartmentAdmin)
admin.site.register(HospitalModel, HospitalAdmin)
admin.site.register(DoctorModel, DoctorAdmin)
admin.site.register(DoctorTitle, DoctorTitleAdmin)
admin.site.register(DoctorLabel, DoctorLabelAdmin)
admin.site.register(DoctorGoodAtModel, DoctorGoodAtModelAdmin)
admin.site.register(HospitalTitleModel, HospitalTitleModelAdmin)

